package UIComponents
{
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	
	public class RewardWinPanel extends Sprite
	{
		/**
		 * 按钮 
		 */		
		public var centerBtn:MyButton;
		/**
		 * 按钮文字 
		 */		
		public var btnTxt:TextField;
		
		public function RewardWinPanel()
		{
			init();
		}
		
		private function init():void
		{
			this.centerBtn=this.getChildByName("btn") as MyButton;
			this.centerBtn.mouseChildren=false;
			this.btnTxt=this.getChildByName("btn_txt") as TextField;
			this.btnTxt.selectable=false;
			this.btnTxt.mouseEnabled=false;
			this.centerBtn.addEventListener(ComponentEvent.BUTTON_DOWN,clickFun);
		}
		
		private function clickFun(ce:ComponentEvent):void
		{
//			this.centerBtn.dispatchEvent(new Event("shareSomething");
			this.dispatchEvent(new Event("shareSomething"));
		}
		
		public function getRewardItemByIndex(index:int,layer:int):RewardItemFrame
		{
			if(layer<0 || layer>6)throw new Error("索引出错");
			return (this.getChildByName("layerItem"+layer+index)) as RewardItemFrame;
		}
		
		public function setRewardItems(arr:Array):void
		{
			setVisabel();
			var layer:int=arr.length;
			for(var i:int=0;i<layer;i++)
			{
				var frame:RewardItemFrame=this.getRewardItemByIndex(i,layer);
				frame.visible=true;
				frame.setItemFrameData(arr[i]);
			}
		}
		
		private function setVisabel():void
		{
			for(var i:int=1;i<=6;i++)
			{
				for(var j:int=0;j<i;j++)
				{
					var frame:RewardItemFrame=this.getRewardItemByIndex(j,i);
					frame.visible=false;
				}
			}
		}
	}
}